package com.xy.servicemanage.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.servicemanage.ServicePage;
import com.ruoyi.common.core.domain.servicemanage.ServiceSpecifications;
import com.xy.servicemanage.service.IServicePageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 服务规格Controller
 *
 * @author ruoyi
 * @date 2025-06-21
 */
@RestController
@RequestMapping("/page")
public class ServicePageController extends BaseController
{
    @Autowired
    private IServicePageService servicePageService;

    /**
     * 查询服务规格列表
     */
    @RequiresPermissions("servicemanage:page:list")
    @GetMapping("/list")
    public TableDataInfo list(ServicePage servicePage)
    {
        startPage();
        List<ServicePage> list = servicePageService.selectServicePageList(servicePage);
        return getDataTable(list);
    }

    /**
     * 导出服务规格列表
     */
    @RequiresPermissions("servicemanage:page:export")
    @Log(title = "服务规格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServicePage servicePage)
    {
        List<ServicePage> list = servicePageService.selectServicePageList(servicePage);
        ExcelUtil<ServicePage> util = new ExcelUtil<ServicePage>(ServicePage.class);
        util.exportExcel(response, list, "服务规格数据");
    }

    /**
     * 获取服务规格详细信息
     */
    @RequiresPermissions("servicemanage:page:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(servicePageService.selectServicePageById(id));
    }

    /**
     * 新增服务规格
     */
    @RequiresPermissions("servicemanage:page:add")
    @Log(title = "服务规格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServicePage servicePage)
    {
        return toAjax(servicePageService.insertServicePage(servicePage));
    }

    /**
     * 修改服务规格
     */
    @RequiresPermissions("servicemanage:page:edit")
    @Log(title = "服务规格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServicePage servicePage)
    {
        return toAjax(servicePageService.updateServicePage(servicePage));
    }

    /**
     * 删除服务规格
     */
    @RequiresPermissions("servicemanage:page:remove")
    @Log(title = "服务规格", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(servicePageService.deleteServicePageByIds(ids));
    }

    /**
     * 查询服务规格
     * @param pageId
     * @return
     */
    @GetMapping("/selectServicePageList1/{pageId}")
    public List<ServiceSpecifications> selectServicePageList1(@PathVariable Long pageId)
    {
        return servicePageService.selectServicePageList1(pageId);
    }
}

